import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CommHttpService } from '../../core/comm.http.service';
import { SERVERS_NAME } from '../../config/config';
import { HttpService } from '../../core/http.service';
import { CopyUtil } from '../../utils/copy.util';
import { Md5 } from 'ts-md5';

@Injectable()
export class PersonalCenterService extends CommHttpService {
  protected preUrl = `${SERVERS_NAME.SECURITY_SERVER}sys/teacher/`;

  constructor(protected http: HttpService) {
    super(http);
  }

  /**
   * 查询部门
   */
  getDepartment() {
    return this.http.get({}, `${SERVERS_NAME.SECURITY_SERVER}` + 'sys/dept/list');
  }

  /**
   * 查询职务/职称
   */
  positionList(param) {
    return this.http.post({}, `${SERVERS_NAME.SECURITY_SERVER}` + 'sys/dictionary/listByType/' + param);
  }

  /**
   * 检查旧密码
   * @param param 密码对象
   */
  checkPass(param: any): Observable<any> {
    const c = CopyUtil.copy(param);
    c.oldPass = Md5.hashStr(c.oldPass).toString();
    return this.http.post(c, `${SERVERS_NAME.SECURITY_SERVER}sys/user/checkPass`, false);
  }


  /**
   * 修改密码
   * @param param 密码对象
   */
  updatePass(param: any): Observable<any> {
    const c = CopyUtil.copy(param);
    c.oldPass = Md5.hashStr(c.oldPass).toString();
    c.newPass = Md5.hashStr(c.newPass).toString();
    return this.http.post(c, `${SERVERS_NAME.SECURITY_SERVER}sys/user/updatePass`);
  }

}
